//
//  WinOption.m
//  HealthAsk
//
//  Created by liyuhang on 12-8-22.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "WinOption.h"
#import "MainWin.h"
#import "AppDelegate.h"

extern Boolean bSound;

@implementation WinOption
//@synthesize bSound;
+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	WinOption *layer = [[WinOption alloc] init];
	
	// add layer as a child to scene
	[scene addChild: layer];
    
  	// return the scene
	return scene;
}

-(WinOption*)init
{
    if ((self=[super init])) {
      //  id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
      //  appDelegate.bSound;
       
        //bSound = TRUE;
        NSString * _pSelgameShop = @"返回";
        CCMenuItem *_itemSel4 = [CCMenuItemFont itemWithString:_pSelgameShop block:^(id sender) {
            [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainWin scene] withColor:ccWHITE]];
        }];
        [_itemSel4 setPosition:ccp(-120,-200)];        // Leaderboard Menu Item using blocks
        
        
        NSString * _pSelgameSound ;
        if (bSound) {
            _pSelgameSound = @"音乐开";
        }else{
            _pSelgameSound = @"音乐关";
        }
        CCMenuItem *_itemSel1 = [CCMenuItemFont itemWithString:_pSelgameSound block:^(id sender) {
            bSound = !bSound;
            [self reload];
        }];
        [_itemSel1 setPosition:ccp(0,0)];        // Leaderboard Menu Item using blocks
        
        m_pMenu = [CCMenu menuWithItems: _itemSel4,_itemSel1, nil];
       // [m_pMenu setPosition:ccp(0,0)];
		[self addChild:m_pMenu];    }
    return self;
}
-(void)reload{
    [m_pMenu removeAllChildrenWithCleanup:YES];
    NSString * _pSelgameShop = @"返回";
    CCMenuItem *_itemSel4 = [CCMenuItemFont itemWithString:_pSelgameShop block:^(id sender) {
        [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainWin scene] withColor:ccWHITE]];
    }];
    [_itemSel4 setPosition:ccp(-120,-200)];        // Leaderboard Menu Item using blocks
    
    
    NSString * _pSelgameSound ;
    if (bSound) {
        _pSelgameSound = @"音乐开";
    }else{
        _pSelgameSound = @"音乐关";
    }
    CCMenuItem *_itemSel1 = [CCMenuItemFont itemWithString:_pSelgameSound block:^(id sender) {
        bSound = !bSound;
        [self reload];
    }];
    [_itemSel1 setPosition:ccp(0,0)];        // Leaderboard Menu Item using blocks
    
    m_pMenu = [CCMenu menuWithItems: _itemSel4,_itemSel1, nil];
    // [m_pMenu setPosition:ccp(0,0)];
    [self addChild:m_pMenu];    
}
@end
